package com.jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class ConsumerDemo {

	public static void main(String[] args) throws JMSException {
		
		ConnectionFactory cf=new ActiveMQConnectionFactory(
				"failover:tcp://localhost:61616");
		System.out.println(cf);
		Connection conn=cf.createConnection();
//		Session session=conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		//
		Session session=conn.createSession(true, Session.SESSION_TRANSACTED);
		Destination queue=new ActiveMQQueue("heather2017");
		MessageConsumer consumer=session.createConsumer(queue);
		
		conn.start();
		
		TextMessage tm=(TextMessage) consumer.receive();
		System.out.println(tm.getText());
		session.commit();//Client AUTO_ACKNOWLEDGE
		tm.acknowledge();//true
		consumer.close();
		session.close();
		conn.close();
	}
}
